package sketch.issta11.specifyvalues;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

//import org.apache.commons.collections.set.ListOrderedSet;

import sketch.ounit.Values;
import sketch.specs.annotation.TestSketch;
import junit.framework.TestCase;

public class Z_ChooseOneValue_Example extends TestCase {
	
	@TestSketch
	public void testChooseSingleValue_foo() {
		int v = Values.choose(1, 2, 3, 4);
		foo(v);
	}
	
	@TestSketch
	public void testChooseSingleValue_bar() {
		int v = Values.choose(5, 6, 7);
		bar(v);
	}
	
	@TestSketch
	public void testChooseMultipleVar_foo2() {
		int v1 = Values.choose(1, 2);
		int v2 = Values.choose(3, 4);
		foo2(v1, v2);
	}
	
	@TestSketch
	public void testChooseMultipleVarPlaces_foo_bar() {
		int v1 = Values.choose(1, 2);
		foo(v1);
		int v2 = Values.choose(3, 4);
		bar(v2);
	}
	
	@TestSketch
	public void testChooseMultipleVar_combine() {
		int v1 = Values.choose(1, 2);
		foo(v1);
		int v2 = Values.choose(3, 4);
		int v3 = Values.choose(5, 6);
		foo2(v2, v3);
	}
	
	@TestSketch
	public void testReceiverAndArgs() {
		String a = "xxx";
		String b = "ccc";
		String v = Values.choose(a, b);
		int index = Values.choose(1, 2, 3);
		v.charAt(index);
	}
	
	@TestSketch
	public void testTryCatch() {
		int v1 = Values.choose(1, 2);
		try {
			foo(v1);
		} catch (Exception e) {
			//ok
		}
	}
	
	@TestSketch public void testDecorator() {
		
    	try {
    		Set s = Values.choose((Set)null, new HashSet());
        	List l = Values.choose((List)null, new ArrayList());
    		{/*@ChooseOne*/
    			list(l);
    			set(s);
    			setlist(s,l);
    		}
    		fail();
    	} catch (IllegalArgumentException ex) {}
    }
	
	@TestSketch
	public void testTryCatchBlock() {
		
		try {
			int v1 = Values.choose(1, 2);
			{/*@ChooseOne*/
			    foo(v1);
			    bar(1);
			}
		} catch (Exception e) {
			//ok
		}
	}
	
	@TestSketch
	public void testMixChooseOne_Values() {
		int i = Values.choose(1, 2, 3);
		foo(i);
		{/*@ChooseOne*/
			bar(1);
			bar(2);
		}
	}
//	
//	@TestSketch
//	public void testTryCatchBlock_2() {
//		
//		try {
//			{int v1 = Values.choose(1, 2);
//			foo(v1);}
//		} catch (Exception e) {
//			//ok
//		}
//	}
	
	@TestSketch
	public void testChooseOne_third() {
		int i1 = 1;
		int i2 = 2;
		int i = Values.choose(i1, i2);
		foo2(i, 1);
		foo2(i, 2);
	}
	
	public void foo(int i) {}
	public void bar(int i) {}
	public void foo2(int i, int j) {}
	
	public void list(List l) {}
	public void set(Set s){};
	public void setlist(Set s , List l) {}
}